package com.xieyong.leetcode;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Leetcode2099 {
    public static void main(String[] args) {
        Leetcode2099 leetcode = new Leetcode2099();
        int[] nums = {2,1,3,3};
        int k = 2;
        int[] ints = leetcode.maxSubsequence(nums, k);
        for (int anInt : ints) {
            System.out.print(anInt + " ");
        }
    }


    public int[] maxSubsequence(int[] nums, int k) {
        int n = nums.length;
        int[][] list = new int[n][2];
        for (int i = 0; i < n; i++) {
            list[i][0] = i;
            list[i][1] = nums[i];
        }
        Arrays.sort(list, (x1, x2) -> Integer.compare(x2[1], x1[1]));
        Arrays.sort(list, 0, k, (x1, x2) -> Integer.compare(x1[0], x2[0]));
        int[] ans = new int[k];
        for (int i = 0; i < k; i++) {
            ans[i] = list[i][1];
        }
        return ans;
    }
}
